cmake_minimum_required(VERSION 3.5)
set(PROJECT_NAME MkCore)
project(${PROJECT_NAME})

set(VERSION "2.0.0.0")
option(BUILD_SHARED "build share lib" OFF)
option(BUILD_SAMPLES "build samples" OFF) 
option(BUILD_UT "build ut" OFF)
set(ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})

set(CMAKE_VERBOSE_MAKEFILE ON)
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_LIST_DIR}")
set(CMAKE_CXX_STANDARD 11)

if(MSVC)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
    add_compile_options(/wd4251)
    add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS -D__STDC_LIMIT_MACROS)
    list(APPEND LIBS ws2_32 winmm)
else()
    #execute_process(COMMAND mkdir ${THIRD_BUILD_PATH})
    #execute_process(COMMAND mkdir ${THIRD_LIB_PATH})
    #execute_process(COMMAND mkdir ${THIRD_INCLUDE_PATH})
	#execute_process(COMMAND ${ROOT_PATH}/build_depends.sh ${THIRD_ROOT_PATH} ${THIRD_BUILD_PATH})
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
    list(APPEND LIBS pthread dl)
endif()
find_package(jsoncpp QUIET)
if(jsoncpp_FOUND)
	if(MSVC)
        get_target_property(JSON_INC_PATH jsoncpp_lib_static INTERFACE_INCLUDE_DIRECTORIES)
        include_directories(${JSON_INC_PATH})
        message("FOUND CONFIG: ${jsoncpp_LIBRARIES}")
        message("INCLUDE DIRS: ${JSON_INC_PATH}")
        message("LIBRARIES: ${jsoncpp_INCLUDE_DIRS}")
        LIST(APPEND LIBS jsoncpp_lib_static)
    else()
        INCLUDE(FindPkgConfig)
        pkg_check_modules(JSONCPP REQUIRED jsoncpp)
        include_directories(${JSONCPP_INCLUDE_DIRS})
        message("include path:${JSONCPP_INCLUDE_DIRS}")
        message("lib path:${JSONCPP_LIBRARIES}")
        LIST(APPEND LIBS ${JSONCPP_LIBRARIES})
    endif()	   
else()
	message(FATAL_ERROR "please install jsoncpp  first")
endif()

if(MSVC)
	find_package(tinyxml2 QUIET)
	if(NOT tinyxml2_FOUND)
		message(FATAL_ERROR "please install tinyxml2(https://github.com/leethomason/tinyxml2)  first")
	endif()
	include_directories("C:/Program Files (x86)/tinyxml2/include")
	link_directories("C:/Program Files (x86)/tinyxml2/lib")
endif(MSVC)
list(APPEND LIBS  tinyxml2)

if (BUILD_UT)
    add_subdirectory(Ut)
    SET_TARGET_PROPERTIES(UtCore PROPERTIES FOLDER ut)
endif()

if (BUILD_SAMPLES)
    add_definitions(-DMkSample)
	add_subdirectory(Sample)
	SET_TARGET_PROPERTIES(SampleWebSocketClient SampleHttpClient PROPERTIES FOLDER sample)
	SET_TARGET_PROPERTIES(SampleTimer PROPERTIES FOLDER sample)
	SET_TARGET_PROPERTIES(SampleTcpServer SampleTcpClient SamplePipe PROPERTIES FOLDER sample)
	SET_TARGET_PROPERTIES(SampleRtp PROPERTIES FOLDER sample)
	SET_TARGET_PROPERTIES(SampleRtspPlayer SampleRtspServer SampleRtspPublisher PROPERTIES FOLDER sample)
	SET_TARGET_PROPERTIES(SampleFlv PROPERTIES FOLDER sample)
	SET_TARGET_PROPERTIES(SamplePs PROPERTIES FOLDER sample)
	SET_TARGET_PROPERTIES(SampleRtmpPusher SampleRtmpPlayer  PROPERTIES FOLDER sample)
	SET_TARGET_PROPERTIES(SampleGbLow SampleGbUp SampleGbDevice SampleGbMediaServer SampleGbMediaEndUser PROPERTIES FOLDER sample)
	SET_TARGET_PROPERTIES(SampleStateGridAUp SampleStateGridALow PROPERTIES FOLDER sample)
	SET_TARGET_PROPERTIES(SampleStateGridBSvr SampleStateGridBClient PROPERTIES FOLDER sample)
	SET_TARGET_PROPERTIES(SampleHttpApiServer PROPERTIES FOLDER sample)
	SET_TARGET_PROPERTIES(SampleHttpMediaServer SampleWsFlvClient PROPERTIES FOLDER sample)
   SET_TARGET_PROPERTIES(SampleHttpHooker SampleHttpClientPool PROPERTIES FOLDER sample)
endif()

add_subdirectory(Source)

